home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-08-26 | 10.4 KB | 396 lines | [TEXT/RWar] |
- ; Robot Name: Chicken
- ;
- ; Trys to dodge in the corner or run away until there is only one other robot
- ; left. Then it turns into a seeker. This robot uses the concept of behavior
- ; routines that can be repeatably called to provide a specific strategy.
- ; Each behavior routine may then select a different behavior routine in
- ; different situations.
- ; An improvement would be to know about walls and try to keep from getting
- ; cornered by dodging into the open to a far corner, even if it means moving
- ; closer to a robot in order to squeeze by it.
-
- CPU_SPEED 0
- ARMOR 0
- FIRE_RATE 2
- ENGINE_SIZE 0
- RADAR_RANGE 1
- CLOAKING 1
- FUEL_CAPACITY 2
-
- allocate midX
- allocate midy
- allocate quadrant
- allocate currentBehaviorRoutine
- allocate cornerCheckRoutine
- allocate quadrantDirection
- allocate doneMovingToCorner
- allocate clockTicks
- allocate timeInterruptBehaviorRoutine
- allocate circleSearchAim
- allocate aimIncrement
- allocate usingRadar ;Semaphore used to tell interrupt code that radar register is in use
- allocate mainLineRadar
- allocate cornerDodgeDirection
- allocate oldDamage
- allocate oldAim
-
- define kSafetyDistance 20
- define false 0
- define true 1
- define kDodgeOutDistance 60
-
- XMAX/2 to midx
- YMAX/2 to midy
- false to usingRadar
- 0 to clockTicks to circleSearchAim
- GeneralInterrupt to timeInterruptBehaviorRoutine
- TimeInterruptRoutine to time_int_xfer
- 1 to time_int_mask
- 0 to oldDamage
-
- if num_robots = 1 then
- Seeker to currentBehaviorRoutine
- else
- MoveTowardsCorner to currentBehaviorRoutine
- end
-
- ;This is the Master Control Program that simply calls the current behavior routine.
- again
- gosub currentBehaviorRoutine
- goto again
-
- NullRoutine
- return
-
- ; Behaviour routine: DodgeBackAndForth
- ;
- ; This routine is utilized when a robot is finally in a corner and just wants
- ; to dodge back and forth in and out of the corner. the cornerDodgeDirection
- ; is assumed to be initialized. If the robot collides, then it will move back
- ; into the corner.
-
- DodgeBackAndForth
- 20 to speed
- cornerDodgeDirection to direction
- DodgingOut to currentBehaviorRoutine
- DodgingOut ;Dodging in will be done by
- if num_robots = 1 then Seeker to currentBehaviorRoutine
- gosub LookAndShoot
- if speed = 0 then
- gosub MoveTowardsCorner
- else
- if quadrant <= 2 then ;Check for right wall, else left wall
- if XMAX - kDodgeOutDistance > x then
- cornerDodgeDirection + 180 to direction
- gosub MoveTowardsCorner
- end
- else
- if x > kDodgeOutDistance then
- cornerDodgeDirection + 180 to direction
- gosub MoveTowardsCorner
- end
- end
- end
- return
-
- ; Behavior routine: MoveTowardsCorner
- ;
- ; Initializes by beginning to move into the nearest corner, then switches to
- ; ContinueMovingToCorner as the behavior routine.
- ; ContinueMovingToCorner
- ; tries to safely move to the corner while avoiding collisions yet shooting
- ; the closest robot. When the corner is found, switches to the
- ; DodgeBackAndForth Behavior routine.
-
- MoveTowardsCorner
- gosub FindQuadrant
- BeginMoveTowardsQuadrant
- gosub InitMoveTowardsQuadrant
- direction to quadrantDirection
- 20 to speed
- ContinueMovingToCorner to currentBehaviorRoutine
- false to doneMovingToCorner
- 17 to aimIncrement
- return
-
-
- ;Find the closest quadrant.
- ;Starting with the upper right, quadrants are 1,2,3,4 clockwise
-
- FindQuadrant
- if x < midx then
- if y < midy then
- 4 to quadrant
- else
- 3 to quadrant
- end
- else
- if y < midy then
- 1 to quadrant
- else
- 2 to quadrant
- end
- end
- return
-
-
-
- InitMoveTowardsQuadrant
- if quadrant = 1 then
- XMAX-x to X_Conv
- 0-y to Y_Conv
- Angle_Conv to direction
- quad1 to cornerCheckRoutine
- else
- if quadrant = 2 then
- XMAX-x to X_Conv
- YMAX-y to Y_Conv
- Angle_Conv to direction
- quad2 to cornerCheckRoutine
- else
- if quadrant = 3 then
- 0-x to X_Conv
- YMAX-y to Y_Conv
- Angle_Conv to direction
- quad3 to cornerCheckRoutine
- else
- 0-x to X_Conv
- 0-y to Y_Conv
- Angle_Conv to direction
- quad4 to cornerCheckRoutine
- end
- end
- end
- return
-
-
-
-
- ; Behavior routine: ContinueMovingToCorner
- ;
- ; ContinueMovingToCorner tries to safely move to the assigned corner while avoiding
- ; collisions, yet shooting at the closest robot. When the corner is found,
- ; switches to the DodgeBackAndForth Behavior routine.
-
- ContinueMovingToCorner
- if num_robots = 1 then Seeker to currentBehaviorRoutine
- if speed = 0 then
- -20 to speed
- true to doneMovingToCorner
- else
- gosub cornerCheckRoutine
- end
- if doneMovingToCorner = true then
- DodgeBackAndForth to currentBehaviorRoutine
- else
- gosub LookAndShoot
- end
- return
-
- ; Corner Check Routines;
- ;
- ; In the quadrant corner detectors, stop the robot only when both X and Y
- ; directions are close to the wall.
-
- quad1
- if XMAX-kSafetyDistance < x then
- 0 to direction
- if y < kSafetyDistance then
- 0 to speed
- TRUE to doneMovingToCorner
- 215 to cornerDodgeDirection
- end
- else
- if y < kSafetyDistance then 90 to direction
- end
- return
-
- quad2
- if XMAX-kSafetyDistance < x then
- 180 to direction
- if YMAX-kSafetyDistance < y then
- 0 to speed
- TRUE to doneMovingToCorner
- 305 to cornerDodgeDirection
- end
- else
- if YMAX-kSafetyDistance < y then 90 to direction
- end
- return
-
- quad3
- if x < kSafetyDistance then
- 180 to direction
- if YMAX-kSafetyDistance < y then
- 0 to speed
- TRUE to doneMovingToCorner
- 45 to cornerDodgeDirection
- end
- else
- if YMAX-kSafetyDistance < y then 270 to direction
- end
- return
-
- quad4
- if x < kSafetyDistance then
- 0 to direction
- if y < kSafetyDistance then
- 0 to speed
- TRUE to doneMovingToCorner
- 135 to cornerDodgeDirection
- end
- else
- if y < kSafetyDistance then 270 to direction
- end
- return
-
-
-
- LookAndShoot
- true to usingRadar ;lock out interrupt routine
- aim + aimIncrement to aim to radar
- radar to mainLineRadar ;Save value so interrupt routine can use radar
- false to usingRadar
- if mainLineRadar > 0 then
- if mainLineRadar < 100 then gosub CloakMe
- if shot = 0 then
- mainLineRadar to shot
- else
- aim - aimIncrement - 1 to aim
- end
- 1 to aimIncrement
- else
- aimIncrement + 1 to aimIncrement
- if aimIncrement > 17 then 17 to aimIncrement
- end
- return
-
-
- ; Look ahead for collision and check for damage. This is a time interrupt behavior routine ment to
- ; be called during interrupt time.
- GeneralInterrupt
- if damage <> oldDamage then
- gosub CloakMe
- damage to oldDamage
- end
- if usingRadar <> true then ;Use semaphore so we don't mess up mainline variables.
- direction to radar
- if radar > 0 then
- if radar < 100 then
- if shot = 0 then radar to shot
- quadrant mod 4 + 1 to quadrant
- gosub BeginMoveTowardsQuadrant
- end
- end
- end
- return
-
-
-
- ; Behavior routine: Seeker
- ;
- ; Seeks out and chases down enemy robot while trying not to collide with it.
- Seeker
- NullRoutine to timeInterruptBehaviorRoutine
- ContinueSeeker to currentBehaviorRoutine
-
- ;Start off towards the center of the arena
- if x < 180 then
- if y < 150 then
- 135 to direction ;in upper left, move towards lower right
- else
- 45 to direction ;in lower left, move towards upper right
- end
- else
- if y < 150 then
- 225 to direction ;in upper right, move towards lower left
- else
- 315 to direction ;in lower right, moved towards upper left
- end
- end
- 20 to speed
-
- ContinueSeeker
- repeat
- if speed = 0 then
- gosub CloakMe
- 120 + direction to direction ;Move away from possible collision source
- 20 to speed
- end
- if X < 20 then 90 to direction
- if Y < 20 then 180 to direction
- if X > 360 then 270 to direction
- if Y > 290 then 0 to direction
- if damage <> oldDamage then gosub CloakMe
- aim + 3 to aim
- true to usingRadar ;lock out interrupt routine
- aim to radar
- radar to mainLineRadar
- false to usingRadar
- until mainLineRadar > 0
-
- aim to direction
- if mainLineRadar < 80 then gosub CloakMe
-
- ;Try to avoid hitting the other robot
-
- if mainLineRadar < 110 then aim - 10 to direction
- if mainLineRadar < 85 then aim - 30 to direction
- if mainLineRadar < 45 then
- aim - 120 to direction
- else
- if mainLineRadar < 85 then aim - 40 to direction
- end
-
- if shot > 0 then
- aim - 9 to aim
- else
- aim to oldAim
- 300/mainLineRadar + aim - 1 to aim ;Try to hit the center of the enemy robot
-
- ;Usually enemy robots are moving away, shoot ahead of them.
- mainLineRadar / 10 + mainLineRadar to shot
-
- oldAim to aim
- aim - 4 to aim
- end
- return
-
-
- ;Try to hide while conserving fuel
-
- CloakMe
- damage to oldDamage
- if damage > 75 then ;about to die
- fuel/50 to cloak
- if damage > 90 then cloak + 10 to cloak ;really about to die
- else
- if fuel < 150 then ;almost out of fuel don't cloak to much
- 2 to cloak ;Only cloak enough to possibly trick other robot.
- if damage > 95 then 5 to cloak ;Also about to die, oh no!
- else
- if fuel > 1500 then ;Lots of fuel, clock for awhile
- 12 to cloak
- else
- if fuel > 750 then ;Not as much fuel, don't cloak as long
- 10 to cloak
- else
- 5 to cloak ;Not much fuel
- end
- end
- end
- end
- return
-
-
-
-
-
- ; Time interrupt routine simply keeps a clock count and calls the
- ; current interrupt Behavior routine.
-
- TimeInterruptRoutine
- clockTicks + 1 to clockTicks
- if cloak > 0 then cloak - 1 to cloak
- gosub timeInterruptBehaviorRoutine
- endint